package com.ymatou.iapi.couponmanage.old.testcase;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.couponmanage.old.parameter.CouponValue;
import com.ymatou.iapi.couponmanage.old.parameter.CreateCouponBean;
import com.ymatou.iapi.couponmanage.old.service.CreateCouponCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.database.model.YmtCoupon;
import com.ymttest.database.model.YmtCouponBatch;
import com.ymttest.database.model.YmtCouponGenerateSubTask;
import com.ymttest.database.model.YmtCouponGenerateTask;
import com.ymttest.database.model.YmtCouponScenario;
import com.ymttest.database.model.YmtCouponSetting;
import com.ymttest.database.model.YmtCouponValue;
import com.ymttest.database.sqlwapper.YmtCouponBatchWapper;
import com.ymttest.database.sqlwapper.YmtCouponGenerateSubTaskWapper;
import com.ymttest.database.sqlwapper.YmtCouponGenerateTaskWapper;
import com.ymttest.database.sqlwapper.YmtCouponScenarioWapper;
import com.ymttest.database.sqlwapper.YmtCouponSequenceWapper;
import com.ymttest.database.sqlwapper.YmtCouponSettingWapper;
import com.ymttest.database.sqlwapper.YmtCouponValueWapper;
import com.ymttest.database.sqlwapper.YmtCouponWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.TestDataManager;

/**
 * 创建批次接口 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_CreateCoupon {
    private static CreateCouponBean createcouponBean;
    private static CreateCouponCall createcouponCall;

    @BeforeClass
    public static void setUp() {
        Logger.createResultFile("创建批次接口");
    }

    @Before
    public void caseUp() {
        createcouponBean = new CreateCouponBean();
        createcouponCall = new CreateCouponCall();
    }

    @AfterClass
    public static void tearDown() {
        Logger.generateResult(createcouponCall.getOpurl());
    }

    @After
    public void caseDown() {
        Logger.end();
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_001() {
        Logger.start(true, "正例-创建批次-SendType为1:短码发放（需要创建子任务）");
        try {

            setDefaultCreateCouponBean();
            int oldSequenceCount = new YmtCouponSequenceWapper()
                    .selectByPrimaryKey(1).getSequenceCount();

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            verifyReturn(oldSequenceCount);

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_002() {
        Logger.start(true, "正例-创建批次-SendType为2:链接发放(创建子任务)");
        try {
            setLinkCreateCouponBean();

            int newSequenceCount = new YmtCouponSequenceWapper()
                    .selectByPrimaryKey(1).getSequenceCount();

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            verifyReturn(newSequenceCount);

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_003() {
        Logger.start(true, "正例-创建批次-短码-UserType为0：全部用户");
        try {

            setDefaultCreateCouponBean();
            createcouponBean.setUserType(0);

            int newSequenceCount = new YmtCouponSequenceWapper()
                    .selectByPrimaryKey(1).getSequenceCount();

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            verifyReturn(newSequenceCount);

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_004() {
        Logger.start(true, "正例-创建批次-短码-UserType为1：新用户");
        try {

            setDefaultCreateCouponBean();
            createcouponBean.setUserType(1);

            int newSequenceCount = new YmtCouponSequenceWapper()
                    .selectByPrimaryKey(1).getSequenceCount();

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            verifyReturn(newSequenceCount);

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_005() {
        Logger.start(true, "正例-创建批次-短码-UserType为2：老用户");
        try {

            setDefaultCreateCouponBean();
            createcouponBean.setUserType(2);

            int newSequenceCount = new YmtCouponSequenceWapper()
                    .selectByPrimaryKey(1).getSequenceCount();

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            verifyReturn(newSequenceCount);

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_006() {
        Logger.start(true, "正例-创建批次-短码-UsePlatforms下单平台限制：不传为无限制");
        try {

            setDefaultCreateCouponBean();

            int newSequenceCount = new YmtCouponSequenceWapper()
                    .selectByPrimaryKey(1).getSequenceCount();

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            verifyReturn(newSequenceCount);

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_007() {
        Logger.start(true, "正例-创建批次-短码-UsePlatforms下单平台限制：PC：1");
        try {

            setDefaultCreateCouponBean();

            List<Integer> list = new ArrayList<Integer>();
            list.add(1);

            createcouponBean.setUsePlatforms(list);

            int newSequenceCount = new YmtCouponSequenceWapper()
                    .selectByPrimaryKey(1).getSequenceCount();

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            verifyReturn(newSequenceCount);

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_008() {
        Logger.start(true, "正例-创建批次-短码-UsePlatforms下单平台限制：PC：6");
        try {

            setDefaultCreateCouponBean();

            List<Integer> list = new ArrayList<Integer>();
            list.add(6);

            createcouponBean.setUsePlatforms(list);

            int newSequenceCount = new YmtCouponSequenceWapper()
                    .selectByPrimaryKey(1).getSequenceCount();

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            verifyReturn(newSequenceCount);

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_009() {
        Logger.start(true, "正例-创建批次-短码-UsePlatforms下单平台限制：PC：12");
        try {

            setDefaultCreateCouponBean();

            List<Integer> list = new ArrayList<Integer>();
            list.add(12);

            createcouponBean.setUsePlatforms(list);

            int newSequenceCount = new YmtCouponSequenceWapper()
                    .selectByPrimaryKey(1).getSequenceCount();

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            verifyReturn(newSequenceCount);

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_010() {
        Logger.start(true, "正例-创建批次-短码-UsePlatforms下单平台限制：APP：3");
        try {

            setDefaultCreateCouponBean();

            List<Integer> list = new ArrayList<Integer>();
            list.add(3);

            createcouponBean.setUsePlatforms(list);

            int newSequenceCount = new YmtCouponSequenceWapper()
                    .selectByPrimaryKey(1).getSequenceCount();

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            verifyReturn(newSequenceCount);

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_011() {
        Logger.start(true, "正例-创建批次-短码-UsePlatforms下单平台限制：APP：4");
        try {

            setDefaultCreateCouponBean();

            List<Integer> list = new ArrayList<Integer>();
            list.add(4);

            createcouponBean.setUsePlatforms(list);

            int newSequenceCount = new YmtCouponSequenceWapper()
                    .selectByPrimaryKey(1).getSequenceCount();

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            verifyReturn(newSequenceCount);

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_012() {
        Logger.start(true, "正例-创建批次-短码-UsePlatforms下单平台限制：APP：7");
        try {

            setDefaultCreateCouponBean();

            List<Integer> list = new ArrayList<Integer>();
            list.add(7);

            createcouponBean.setUsePlatforms(list);

            int newSequenceCount = new YmtCouponSequenceWapper()
                    .selectByPrimaryKey(1).getSequenceCount();

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            verifyReturn(newSequenceCount);

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_013() {
        Logger.start(true, "正例-创建批次-短码-UsePlatforms下单平台限制：APP：8");
        try {

            setDefaultCreateCouponBean();

            List<Integer> list = new ArrayList<Integer>();
            list.add(8);

            createcouponBean.setUsePlatforms(list);

            int newSequenceCount = new YmtCouponSequenceWapper()
                    .selectByPrimaryKey(1).getSequenceCount();

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            verifyReturn(newSequenceCount);

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_014() {
        Logger.start(true, "正例-创建批次-短码-UsePlatforms下单平台限制：APP：10");
        try {

            setDefaultCreateCouponBean();

            List<Integer> list = new ArrayList<Integer>();
            list.add(10);

            createcouponBean.setUsePlatforms(list);

            int newSequenceCount = new YmtCouponSequenceWapper()
                    .selectByPrimaryKey(1).getSequenceCount();

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            verifyReturn(newSequenceCount);

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_015() {
        Logger.start(true, "正例-创建批次-短码-UsePlatforms下单平台限制：APP：11");
        try {

            setDefaultCreateCouponBean();

            List<Integer> list = new ArrayList<Integer>();
            list.add(11);

            createcouponBean.setUsePlatforms(list);

            int newSequenceCount = new YmtCouponSequenceWapper()
                    .selectByPrimaryKey(1).getSequenceCount();

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            verifyReturn(newSequenceCount);

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_016() {
        Logger.start(true, "正例-创建批次-短码-UsePlatforms下单平台限制：WAP：2");
        try {

            setDefaultCreateCouponBean();

            List<Integer> list = new ArrayList<Integer>();
            list.add(2);

            createcouponBean.setUsePlatforms(list);

            int newSequenceCount = new YmtCouponSequenceWapper()
                    .selectByPrimaryKey(1).getSequenceCount();

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            verifyReturn(newSequenceCount);

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_017() {
        Logger.start(true, "正例-创建批次-短码-UsePlatforms下单平台限制：WAP：5");
        try {

            setDefaultCreateCouponBean();

            List<Integer> list = new ArrayList<Integer>();
            list.add(5);

            createcouponBean.setUsePlatforms(list);

            int newSequenceCount = new YmtCouponSequenceWapper()
                    .selectByPrimaryKey(1).getSequenceCount();

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            verifyReturn(newSequenceCount);

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_018() {
        Logger.start(true, "正例-创建批次-短码-UsePlatforms下单平台限制：WAP：9");
        try {

            setDefaultCreateCouponBean();

            List<Integer> list = new ArrayList<Integer>();
            list.add(9);

            createcouponBean.setUsePlatforms(list);

            int newSequenceCount = new YmtCouponSequenceWapper()
                    .selectByPrimaryKey(1).getSequenceCount();

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            verifyReturn(newSequenceCount);

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_019() {
        Logger.start(true, "正例-创建批次-短码-指定限制商品");
        try {

            setDefaultCreateCouponBean();

            List<Integer> list = new ArrayList<Integer>();
            list.add(999999);

            createcouponBean.setProductIds(list);

            int newSequenceCount = new YmtCouponSequenceWapper()
                    .selectByPrimaryKey(1).getSequenceCount();

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            verifyReturn(newSequenceCount);

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_020() {
        Logger.start(true, "正例-创建批次-短码-指定限制买手");
        try {

            setDefaultCreateCouponBean();

            List<Integer> list = new ArrayList<Integer>();
            list.add(Integer.parseInt(EnvSetup.getData("BuyUserId")));

            createcouponBean.setSellerIds(list);

            int newSequenceCount = new YmtCouponSequenceWapper()
                    .selectByPrimaryKey(1).getSequenceCount();

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            verifyReturn(newSequenceCount);

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_021() {
        Logger.start(true, "正例-创建批次-短码-指定限制活动");
        try {

            setDefaultCreateCouponBean();

            List<Integer> list = new ArrayList<Integer>();
            list.add(1234);

            createcouponBean.setActivityIds(list);

            int newSequenceCount = new YmtCouponSequenceWapper()
                    .selectByPrimaryKey(1).getSequenceCount();

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            verifyReturn(newSequenceCount);

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_022() {
        Logger.start(true, "正例-创建批次-短码-指定限制品牌");
        try {

            setDefaultCreateCouponBean();

            List<Integer> list = new ArrayList<Integer>();
            list.add(1234);

            createcouponBean.setBrands(list);

            int newSequenceCount = new YmtCouponSequenceWapper()
                    .selectByPrimaryKey(1).getSequenceCount();

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            verifyReturn(newSequenceCount);

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_023() {
        Logger.start(true, "正例-创建批次-短码-指定限制分类");
        try {

            setDefaultCreateCouponBean();

            List<Integer> list = new ArrayList<Integer>();
            list.add(1);

            createcouponBean.setCategories(list);

            int newSequenceCount = new YmtCouponSequenceWapper()
                    .selectByPrimaryKey(1).getSequenceCount();

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            verifyReturn(newSequenceCount);

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_024() {
        Logger.start(true, "反例-创建批次-CouponBatch验证-优惠卷生成总数不能小于0");
        try {

            setDefaultCreateCouponBean();
            createcouponBean.setCouponNum(-1);

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            Logger.verifyEquals("2", createcouponCall.getCode(),
                    "验证返回StatusCode值");
            Logger.verifyEquals(true,
                    createcouponCall.getMessage().contains("优惠卷生成总数不能小于0"),
                    "验证返回Message值:优惠卷生成总数不能小于0");

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_025() {
        Logger.start(true, "反例-创建批次-CouponBatch验证-单用户使用最大次数不能小于0");
        try {

            setDefaultCreateCouponBean();
            createcouponBean.setPerUserReceiveMaxCount(-1);

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            Logger.verifyEquals("2", createcouponCall.getCode(),
                    "验证返回StatusCode值");
            Logger.verifyEquals(true,
                    createcouponCall.getMessage().contains("单用户使用最大次数不能小于0"),
                    "验证返回Message值为：单用户使用最大次数不能小于0");

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_026() {
        Logger.start(true, "反例-创建批次-CouponBatch验证-必须提供创建者ID");
        try {

            setDefaultCreateCouponBean();
            createcouponBean.setOperatorId(null);

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            Logger.verifyEquals("2", createcouponCall.getCode(),
                    "验证返回StatusCode值");
            Logger.verifyEquals(true,
                    createcouponCall.getMessage().contains("必须提供创建者ID"),
                    "验证返回Message值为：必须提供创建者ID");

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_027() {
        Logger.start(true, "反例-创建批次-CouponBatch验证-发放方式必须为短码发放或链接发放");
        try {

            setDefaultCreateCouponBean();
            createcouponBean.setSendType(4);

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            Logger.verifyEquals("2", createcouponCall.getCode(),
                    "验证返回StatusCode值");
            Logger.verifyEquals(true,
                    createcouponCall.getMessage().contains("发放方式必须为短码发放或链接发放"),
                    "验证返回Message值为：发放方式必须为短码发放或链接发放");

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_031() {
        Logger.start(true, "反例-创建批次-CouponBatch验证-平台创建优惠卷必须提供预备金");
        try {

            setDefaultCreateCouponBean();
            createcouponBean.setImpresetInvoiceId(null);

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            Logger.verifyEquals("2", createcouponCall.getCode(),
                    "验证返回StatusCode值");
            Logger.verifyEquals(true,
                    createcouponCall.getMessage().contains("平台创建优惠卷必须提供预备金"),
                    "验证返回Message值为：平台创建优惠卷必须提供预备金");

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_032() {
        Logger.start(true, "反例-创建批次-CouponBatch验证-平台创建优惠卷必须提供申请部门");
        try {

            setDefaultCreateCouponBean();
            createcouponBean.setDepartment(null);

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            Logger.verifyEquals("2", createcouponCall.getCode(),
                    "验证返回StatusCode值");
            Logger.verifyEquals(true,
                    createcouponCall.getMessage().contains("平台创建优惠卷必须提供申请部门"),
                    "验证返回Message值为：平台创建优惠卷必须提供申请部门");

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_034() {
        Logger.start(true, "反例-创建批次-CouponBatch验证-短码发放方式不允许相对有效期");
        try {

            setDefaultCreateCouponBean();
            createcouponBean.setSendType(1);
            createcouponBean.setEffectiveType(1);

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            Logger.verifyEquals("2", createcouponCall.getCode(),
                    "验证返回StatusCode值");
            Logger.verifyEquals(true,
                    createcouponCall.getMessage().contains("短码发放方式不允许相对有效期"),
                    "验证返回Message值为：短码发放方式不允许相对有效期");

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_035() {
        Logger.start(true, "反例-创建批次-CouponBatch验证-链接发放方式单卷使用次数必须为1");
        try {

            setDefaultCreateCouponBean();
            createcouponBean.setSendType(2);
            createcouponBean.setPerCouponMaxUseCount(2);

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            Logger.verifyEquals("2", createcouponCall.getCode(),
                    "验证返回StatusCode值");
            Logger.verifyEquals(true,
                    createcouponCall.getMessage().contains("链接发放方式单卷使用次数必须为1"),
                    "验证返回Message值为：链接发放方式单卷使用次数必须为1");

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_036() {
        Logger.start(true, "反例-创建批次-CouponSetting验证-优惠卷使用类型错误");
        try {

            setDefaultCreateCouponBean();
            createcouponBean.setCouponUseType(5);

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            Logger.verifyEquals("2", createcouponCall.getCode(),
                    "验证返回StatusCode值");
            Logger.verifyEquals(true,
                    createcouponCall.getMessage().contains("优惠卷使用类型错误"),
                    "验证返回Message值为：优惠卷使用类型错误");

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_037() {
        Logger.start(true, "反例-创建批次-CouponSetting验证-单用户使用最大次数不能小于0");
        try {

            setDefaultCreateCouponBean();
            createcouponBean.setPerUserReceiveMaxCount(-1);

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            Logger.verifyEquals("2", createcouponCall.getCode(),
                    "验证返回StatusCode值");
            Logger.verifyEquals(true,
                    createcouponCall.getMessage().contains("单用户使用最大次数不能小于0"),
                    "验证返回Message值为：单用户使用最大次数不能小于0");

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_038() {
        Logger.start(true, "反例-创建批次-CouponSetting验证-本批次最大使用次数必须大于0");
        try {

            setDefaultCreateCouponBean();
            createcouponBean.setPerCouponMaxUseCount(-1);

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            Logger.verifyEquals("2", createcouponCall.getCode(),
                    "验证返回StatusCode值");
            Logger.verifyEquals(true,
                    createcouponCall.getMessage().contains("本批次最大使用次数必须大于0"),
                    "验证返回Message值为：本批次最大使用次数必须大于0");

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_042() {
        Logger.start(true, "反例-创建批次-CouponSetting验证-有效期类型错误");
        try {

            setDefaultCreateCouponBean();
            createcouponBean.setEffectiveType(5);

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            Logger.verifyEquals("2", createcouponCall.getCode(),
                    "验证返回StatusCode值");
            Logger.verifyEquals(true,
                    createcouponCall.getMessage().contains("有效期类型错误"),
                    "验证返回Message值为：有效期类型错误");

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_043() {
        Logger.start(true, "反例-创建批次-CouponSetting验证-相对有效期生效方式错误");
        try {

            setDefaultCreateCouponBean();
            createcouponBean.setSendType(2);
            createcouponBean.setEffectiveType(1);
            createcouponBean.setEffectiveValidType(6);
            createcouponBean.setPerCouponMaxUseCount(1);

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            Logger.verifyEquals("2", createcouponCall.getCode(),
                    "验证返回StatusCode值");
            Logger.verifyEquals(true,
                    createcouponCall.getMessage().contains("相对有效期生效方式错误"),
                    "验证返回Message值为：相对有效期生效方式错误");

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_044() {
        Logger.start(true, "反例-创建批次-CouponSetting验证-相对有效期有效天数必须大于0");
        try {

            setDefaultCreateCouponBean();
            setDefaultCreateCouponBean();
            createcouponBean.setSendType(2);
            createcouponBean.setEffectiveType(1);
            createcouponBean.setEffectiveValidType(1);
            createcouponBean.setPerCouponMaxUseCount(1);
            createcouponBean.setEffectiveDays(0);

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            Logger.verifyEquals("2", createcouponCall.getCode(),
                    "验证返回StatusCode值");
            Logger.verifyEquals(true,
                    createcouponCall.getMessage().contains("相对有效期有效天数必须大于0"),
                    "验证返回Message值为：相对有效期有效天数必须大于0");

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_045() {
        Logger.start(true, "反例-创建批次-CouponSetting验证-绝对有效期错误-setting.ValidEnd < setting.ValidStart");
        try {
            Date dNow = new Date(); // 当前时间
            Date dBefore = new Date();
            Date dAfter = new Date();

            Calendar calendar1 = Calendar.getInstance(); // 得到日历
            calendar1.setTime(dNow);// 把当前时间赋给日历
            calendar1.add(Calendar.DAY_OF_MONTH, -1); // 设置为前一天
            dBefore = calendar1.getTime(); // 得到前一天的时间

            Calendar calendar2 = Calendar.getInstance(); // 得到日历
            calendar2.setTime(dNow);// 把当前时间赋给日历
            calendar2.add(Calendar.DAY_OF_MONTH, 10); // 设置为后十天
            dAfter = calendar2.getTime(); // 得到前一天的时间

            setDefaultCreateCouponBean();
            createcouponBean.setEffectiveType(0);
            createcouponBean.setValidEnd(dBefore);
            createcouponBean.setValidStart(dAfter);

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            Logger.verifyEquals("2", createcouponCall.getCode(),
                    "验证返回StatusCode值");
            Logger.verifyEquals(true,
                    createcouponCall.getMessage().contains("绝对有效期错误"),
                    "验证返回Message值为：绝对有效期错误");

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_028() {
        Logger.start(true,
                "反例-创建批次-CouponSetting验证-绝对有效期错误-setting.ValidEnd < DateTime.Now");
        try {
            Date dNow = new Date(); // 当前时间
            Date dBefore = new Date();
            Date dAfter = new Date();

            Calendar calendar1 = Calendar.getInstance(); // 得到日历
            calendar1.setTime(dNow);// 把当前时间赋给日历
            calendar1.add(Calendar.DAY_OF_MONTH, -1); // 设置为前一天
            dBefore = calendar1.getTime(); // 得到前一天的时间

            Calendar calendar2 = Calendar.getInstance(); // 得到日历
            calendar2.setTime(dNow);// 把当前时间赋给日历
            calendar2.add(Calendar.DAY_OF_MONTH, 10); // 设置为后十天
            dAfter = calendar2.getTime(); // 得到前一天的时间

            setDefaultCreateCouponBean();
            createcouponBean.setEffectiveType(0);
            createcouponBean.setValidEnd(dBefore);

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            Logger.verifyEquals("2", createcouponCall.getCode(),
                    "验证返回StatusCode值");
            Logger.verifyEquals(true,
                    createcouponCall.getMessage().contains("绝对有效期错误"),
                    "验证返回Message值为：绝对有效期错误");

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_046() {
        Logger.start(true, "反例-创建批次-CouponSetting验证-必须提供申请人-null");
        try {

            setDefaultCreateCouponBean();
            createcouponBean.setApplyUser(null);

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            Logger.verifyEquals("2", createcouponCall.getCode(),
                    "验证返回StatusCode值");
            Logger.verifyEquals(true,
                    createcouponCall.getMessage().contains("必须提供申请人"),
                    "验证返回Message值为：必须提供申请人");

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_029() {
        Logger.start(true, "反例-创建批次-CouponSetting验证-必须提供申请人-空字符");
        try {

            setDefaultCreateCouponBean();
            createcouponBean.setApplyUser("");

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            Logger.verifyEquals("2", createcouponCall.getCode(),
                    "验证返回StatusCode值");
            Logger.verifyEquals(true,
                    createcouponCall.getMessage().contains("必须提供申请人"),
                    "验证返回Message值为：必须提供申请人");

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_047() {
        Logger.start(true, "反例-创建批次-CouponSetting验证-必须提供申请理由-null");
        try {

            setDefaultCreateCouponBean();
            createcouponBean.setApplyMemo(null);

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            Logger.verifyEquals("2", createcouponCall.getCode(),
                    "验证返回StatusCode值");
            Logger.verifyEquals(true,
                    createcouponCall.getMessage().contains("必须提供申请理由"),
                    "验证返回Message值为：必须提供申请理由");

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_030() {
        Logger.start(true, "反例-创建批次-CouponSetting验证-必须提供申请理由-空字符");
        try {

            setDefaultCreateCouponBean();
            createcouponBean.setApplyMemo("");

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            Logger.verifyEquals("2", createcouponCall.getCode(),
                    "验证返回StatusCode值");
            Logger.verifyEquals(true,
                    createcouponCall.getMessage().contains("必须提供申请理由"),
                    "验证返回Message值为：必须提供申请理由");

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    /**
     * 该场景无法覆盖到
     */
    @Test
    @Category(P1.class)
    @TestCase
    @Ignore
    public void Tc_CreateCoupon_048() {
        Logger.start(true, "反例-创建批次-CouponSetting验证-优惠卷商品限制类型错误");
        try {

            setDefaultCreateCouponBean();
            createcouponBean.setOperatorId(null);

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            Logger.verifyEquals("2", createcouponCall.getCode(),
                    "验证返回StatusCode值");
            Logger.verifyEquals(true,
                    createcouponCall.getMessage().contains("必须提供创建者ID"),
                    "验证返回Message值为：必须提供创建者ID");

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_049() {
        Logger.start(true, "反例-创建批次-CouponScenario验证-用户类型错误");
        try {

            setDefaultCreateCouponBean();
            createcouponBean.setUserType(9);

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            Logger.verifyEquals("2", createcouponCall.getCode(),
                    "验证返回StatusCode值");
            Logger.verifyEquals(true,
                    createcouponCall.getMessage().contains("用户类型错误"),
                    "验证返回Message值为：用户类型错误");

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_050() {
        Logger.start(true, "反例-创建批次-CouponValue验证-未提供优惠卷面额-values == null");
        try {

            setDefaultCreateCouponBean();
            createcouponBean.setCouponValues(null);

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            Logger.verifyEquals("2", createcouponCall.getCode(),
                    "验证返回StatusCode值");
            Logger.verifyEquals(true,
                    createcouponCall.getMessage().contains("能够抵扣的金额必须大于0"),
                    "验证返回Message值为：能够抵扣的金额必须大于0");

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_033() {
        Logger.start(true, "反例-创建批次-CouponValue验证-未提供优惠卷面额-values.Count == 0");
        try {

            setDefaultCreateCouponBean();

            List<CouponValue> values = new ArrayList<CouponValue>();
            createcouponBean.setCouponValues(values);

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            Logger.verifyEquals("2", createcouponCall.getCode(),
                    "验证返回StatusCode值");
            Logger.verifyEquals(true,
                    createcouponCall.getMessage().contains("能够抵扣的金额必须大于0"),
                    "验证返回Message值为：能够抵扣的金额必须大于0");

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_051() {
        Logger.start(true, "反例-创建批次-CouponValue验证-能够抵扣的金额必须大于0");
        try {

            setDefaultCreateCouponBean();

            List<CouponValue> values = new ArrayList<CouponValue>();
            CouponValue value = new CouponValue();
            value.setDeductionMaxAmount(new BigDecimal(-1));
            values.add(value);
            createcouponBean.setCouponValues(values);

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            Logger.verifyEquals("2", createcouponCall.getCode(),
                    "验证返回StatusCode值");
            Logger.verifyEquals(true,
                    createcouponCall.getMessage().contains("能够抵扣的金额必须大于0"),
                    "验证返回Message值为：能够抵扣的金额必须大于0");

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_052() {
        Logger.start(true, "反例-创建批次-CouponValue验证-订单满多少金额必须大于0");
        try {

            setDefaultCreateCouponBean();

            List<CouponValue> values = new ArrayList<CouponValue>();
            CouponValue value = new CouponValue();
            value.setDeductionMaxAmount(new BigDecimal(1));
            value.setOrderMinAmount(new BigDecimal(0));
            values.add(value);
            createcouponBean.setCouponValues(values);

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            Logger.verifyEquals("2", createcouponCall.getCode(),
                    "验证返回StatusCode值");
            Logger.verifyEquals(true,
                    createcouponCall.getMessage().contains("订单满多少金额必须大于0"),
                    "验证返回Message值为：订单满多少金额必须大于0");

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_053() {
        Logger.start(true, "反例-创建批次-CouponValue验证-订单满足金额必须大于可以抵扣的金额");
        try {

            setDefaultCreateCouponBean();

            List<CouponValue> values = new ArrayList<CouponValue>();
            CouponValue value = new CouponValue();
            value.setDeductionMaxAmount(new BigDecimal(2));
            value.setOrderMinAmount(new BigDecimal(1));
            values.add(value);
            createcouponBean.setCouponValues(values);

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            Logger.verifyEquals("2", createcouponCall.getCode(),
                    "验证返回StatusCode值");
            Logger.verifyEquals(
                    true,
                    createcouponCall.getMessage().contains("订单满足金额必须大于可以抵扣的金额"),
                    "验证返回Message值为：订单满足金额必须大于可以抵扣的金额");

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_054() {
        Logger.start(true, "反例-创建批次-优惠卷发放类型错误");
        try {

            setDefaultCreateCouponBean();
            createcouponBean.setSendType(3);

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            Logger.verifyEquals("2", createcouponCall.getCode(),
                    "验证返回StatusCode值");
            Logger.verifyEquals(true,
                    createcouponCall.getMessage().contains("发放方式必须为短码发放或链接发放"),
                    "验证返回Message值为：发放方式必须为短码发放或链接发放");

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_055() {
        Logger.start(true, "反例-创建批次-创建链接任务不应指定短码");
        try {

            setDefaultCreateCouponBean();
            createcouponBean.setSendType(2);
            createcouponBean.setIsCustomCouponCode(true);
            createcouponBean.setCustomCouponCode("aadf");
            createcouponBean.setPerCouponMaxUseCount(1);

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            Logger.verifyEquals("2", createcouponCall.getCode(),
                    "验证返回StatusCode值");
            Logger.verifyEquals(true,
                    createcouponCall.getMessage().contains("自定义短码必须为短码发放方式"),
                    "验证返回Message值为：自定义短码必须为短码发放方式");

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_056() {
        Logger.start(true, "反例-创建批次-链接发放单卷使用次数必须等于1");
        try {

            setDefaultCreateCouponBean();
            createcouponBean.setSendType(2);
            createcouponBean.setPerCouponMaxUseCount(2);

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            Logger.verifyEquals("2", createcouponCall.getCode(),
                    "验证返回StatusCode值");
            Logger.verifyEquals(true,
                    createcouponCall.getMessage().contains("链接发放方式单卷使用次数必须为1"),
                    "验证返回Message值为：链接发放方式单卷使用次数必须为1");

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_057() {
        Logger.start(true, "反例-创建批次-自定义短码优惠卷数量必须为1");
        try {

            setDefaultCreateCouponBean();
            createcouponBean.setIsCustomCouponCode(true);
            createcouponBean.setSendType(1);

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            Logger.verifyEquals("2", createcouponCall.getCode(),
                    "验证返回StatusCode值");
            Logger.verifyEquals(true,
                    createcouponCall.getMessage().contains("自定义短码优惠卷数量必须为1"),
                    "验证返回Message值为：自定义短码优惠卷数量必须为1");

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_058() {
        Logger.start(true, "反例-创建批次-自定义短码必须为短码发放方式");
        try {

            setDefaultCreateCouponBean();
            createcouponBean.setIsCustomCouponCode(true);
            createcouponBean.setSendType(2);
            createcouponBean.setPerCouponMaxUseCount(1);

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            Logger.verifyEquals("2", createcouponCall.getCode(),
                    "验证返回StatusCode值");
            Logger.verifyEquals(true,
                    createcouponCall.getMessage().contains("自定义短码必须为短码发放方式"),
                    "验证返回Message值为：自定义短码必须为短码发放方式");

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_059() {
        Logger.start(true, "反例-创建批次-自定义短码优惠卷数量必须为1");
        try {

            setDefaultCreateCouponBean();
            createcouponBean.setIsCustomCouponCode(true);
            createcouponBean.setSendType(1);
            createcouponBean.setCouponNum(2);

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            Logger.verifyEquals("2", createcouponCall.getCode(),
                    "验证返回StatusCode值");
            Logger.verifyEquals(true,
                    createcouponCall.getMessage().contains("自定义短码优惠卷数量必须为1"),
                    "验证返回Message值为：自定义短码优惠卷数量必须为1");

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_060() {
        Logger.start(true, "反例-创建批次-自定义短码卷码不能为空");
        try {

            setDefaultCreateCouponBean();

            createcouponBean.setIsCustomCouponCode(true);
            createcouponBean.setSendType(1);
            createcouponBean.setPerCouponMaxUseCount(1);
            createcouponBean.setCouponNum(1);

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            Logger.verifyEquals("2", createcouponCall.getCode(),
                    "验证返回StatusCode值");
            Logger.verifyEquals(true,
                    createcouponCall.getMessage().contains("自定义短码卷码不能为空"),
                    "验证返回Message值为：自定义短码卷码不能为空");

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    /**
     * 场景无法重新
     */
    @Test
    @Category(P1.class)
    @TestCase
    @Ignore
    public void Tc_CreateCoupon_061() {
        Logger.start(true, "反例-创建批次-Usage错误");
        try {

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_062() {
        Logger.start(true, "反例-创建批次-您指定的卷码已经存在");
        try {

            setDefaultCreateCouponBean();

            createcouponBean.setSendType(1);
            createcouponBean.setPerCouponMaxUseCount(1);
            createcouponBean.setCouponNum(1);
            createcouponBean.setIsCustomCouponCode(true);
            createcouponBean.setCustomCouponCode(new YmtCouponWapper()
                    .selectTop1().getsCouponCode());

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            Logger.verifyEquals("2", createcouponCall.getCode(),
                    "验证返回StatusCode值");
            Logger.verifyEquals(true,
                    createcouponCall.getMessage().contains("您指定的卷码已经存在"),
                    "验证返回Message值为：您指定的卷码已经存在");

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_039() {
        Logger.start(true, "反例-创建批次-可为空的对象必须具有一个值");
        try {

            createcouponBean.setIsCustomCouponCode(true);
            createcouponBean.setSendType(1);
            createcouponBean.setPerCouponMaxUseCount(1);
            createcouponBean.setCouponNum(2);

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            Logger.verifyEquals("3", createcouponCall.getCode(),
                    "验证返回StatusCode值");
            Logger.verifyEquals(true,
                    createcouponCall.getMessage().contains("可为空的对象必须具有一个值。"),
                    "验证返回Message值为：可为空的对象必须具有一个值。");

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_063() {
        Logger.start(true, "正例-创建批次-短码-UsePlatforms下多平台限制：3,4,7,8,9,10");
        try {

            setDefaultCreateCouponBean();

            List<Integer> list = new ArrayList<Integer>();
            list.add(3);
            list.add(4);
            list.add(7);
            list.add(8);
            list.add(9);
            list.add(10);

            createcouponBean.setUsePlatforms(list);

            int newSequenceCount = new YmtCouponSequenceWapper()
                    .selectByPrimaryKey(1).getSequenceCount();

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            verifyReturn(newSequenceCount);

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_064() {
        Logger.start(true, "正例-创建批次-短码-指定限制商品列表");
        try {

            setDefaultCreateCouponBean();

            List<Integer> list = new ArrayList<Integer>();
            list.add(999999);
            list.add(888888);
            list.add(777777);
            list.add(666666);

            createcouponBean.setProductIds(list);

            int newSequenceCount = new YmtCouponSequenceWapper()
                    .selectByPrimaryKey(1).getSequenceCount();

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            verifyReturn(newSequenceCount);

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_065() {
        Logger.start(true, "正例-创建批次-短码-指定限制买手列表");
        try {

            setDefaultCreateCouponBean();

            List<Integer> list = new ArrayList<Integer>();
            list.add(Integer.parseInt(EnvSetup.getData("BuyUserId")));
            list.add(Integer.parseInt(EnvSetup.getData("BuyerId")));

            createcouponBean.setSellerIds(list);

            int newSequenceCount = new YmtCouponSequenceWapper()
                    .selectByPrimaryKey(1).getSequenceCount();

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            verifyReturn(newSequenceCount);

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_066() {
        Logger.start(true, "正例-创建批次-短码-指定限制活动列表");
        try {

            setDefaultCreateCouponBean();

            List<Integer> list = new ArrayList<Integer>();
            list.add(1234);
            list.add(2345);
            list.add(3456);

            createcouponBean.setActivityIds(list);

            int newSequenceCount = new YmtCouponSequenceWapper()
                    .selectByPrimaryKey(1).getSequenceCount();

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            verifyReturn(newSequenceCount);

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_067() {
        Logger.start(true, "正例-创建批次-短码-指定限制品牌列表");
        try {

            setDefaultCreateCouponBean();

            List<Integer> list = new ArrayList<Integer>();
            list.add(1234);
            list.add(2345);
            list.add(1267834);

            createcouponBean.setBrands(list);

            int newSequenceCount = new YmtCouponSequenceWapper()
                    .selectByPrimaryKey(1).getSequenceCount();

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            verifyReturn(newSequenceCount);

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_068() {
        Logger.start(true, "正例-创建批次-短码-指定限制分类列表");
        try {

            setDefaultCreateCouponBean();

            List<Integer> list = new ArrayList<Integer>();
            list.add(1);
            list.add(2);
            list.add(3);
            list.add(4);

            createcouponBean.setCategories(list);

            int newSequenceCount = new YmtCouponSequenceWapper()
                    .selectByPrimaryKey(1).getSequenceCount();

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            verifyReturn(newSequenceCount);

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_069() {
        Logger.start(true, "正例-创建批次-链接-UserType为0：全部用户");
        try {

            setLinkCreateCouponBean();
            createcouponBean.setUserType(0);

            int newSequenceCount = new YmtCouponSequenceWapper()
                    .selectByPrimaryKey(1).getSequenceCount();

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            verifyReturn(newSequenceCount);

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_070() {
        Logger.start(true, "正例-创建批次-短码-UserType为1：新用户");
        try {

            setLinkCreateCouponBean();
            createcouponBean.setUserType(1);

            int newSequenceCount = new YmtCouponSequenceWapper()
                    .selectByPrimaryKey(1).getSequenceCount();

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            verifyReturn(newSequenceCount);

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_071() {
        Logger.start(true, "正例-创建批次-短码-UserType为2：老用户");
        try {

            setLinkCreateCouponBean();
            createcouponBean.setUserType(2);

            int newSequenceCount = new YmtCouponSequenceWapper()
                    .selectByPrimaryKey(1).getSequenceCount();

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            verifyReturn(newSequenceCount);

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_072() {
        Logger.start(true, "正例-创建批次-短码-UsePlatforms下单平台限制：不传为无限制");
        try {

            setLinkCreateCouponBean();

            int newSequenceCount = new YmtCouponSequenceWapper()
                    .selectByPrimaryKey(1).getSequenceCount();

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            verifyReturn(newSequenceCount);

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_073() {
        Logger.start(true, "正例-创建批次-短码-UsePlatforms下单平台限制：PC：1");
        try {

            setLinkCreateCouponBean();

            List<Integer> list = new ArrayList<Integer>();
            list.add(1);

            createcouponBean.setUsePlatforms(list);

            int newSequenceCount = new YmtCouponSequenceWapper()
                    .selectByPrimaryKey(1).getSequenceCount();

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            verifyReturn(newSequenceCount);

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_074() {
        Logger.start(true, "正例-创建批次-短码-UsePlatforms下单平台限制：PC：6");
        try {

            setLinkCreateCouponBean();

            List<Integer> list = new ArrayList<Integer>();
            list.add(6);

            createcouponBean.setUsePlatforms(list);

            int newSequenceCount = new YmtCouponSequenceWapper()
                    .selectByPrimaryKey(1).getSequenceCount();

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            verifyReturn(newSequenceCount);

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_075() {
        Logger.start(true, "正例-创建批次-短码-UsePlatforms下单平台限制：PC：12");
        try {

            setLinkCreateCouponBean();

            List<Integer> list = new ArrayList<Integer>();
            list.add(12);

            createcouponBean.setUsePlatforms(list);

            int newSequenceCount = new YmtCouponSequenceWapper()
                    .selectByPrimaryKey(1).getSequenceCount();

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            verifyReturn(newSequenceCount);

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_076() {
        Logger.start(true, "正例-创建批次-短码-UsePlatforms下单平台限制：APP：3");
        try {

            setLinkCreateCouponBean();

            List<Integer> list = new ArrayList<Integer>();
            list.add(3);

            createcouponBean.setUsePlatforms(list);

            int newSequenceCount = new YmtCouponSequenceWapper()
                    .selectByPrimaryKey(1).getSequenceCount();

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            verifyReturn(newSequenceCount);

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_077() {
        Logger.start(true, "正例-创建批次-短码-UsePlatforms下单平台限制：APP：4");
        try {

            setLinkCreateCouponBean();

            List<Integer> list = new ArrayList<Integer>();
            list.add(4);

            createcouponBean.setUsePlatforms(list);

            int newSequenceCount = new YmtCouponSequenceWapper()
                    .selectByPrimaryKey(1).getSequenceCount();

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            verifyReturn(newSequenceCount);

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_078() {
        Logger.start(true, "正例-创建批次-短码-UsePlatforms下单平台限制：APP：7");
        try {

            setLinkCreateCouponBean();

            List<Integer> list = new ArrayList<Integer>();
            list.add(7);

            createcouponBean.setUsePlatforms(list);

            int newSequenceCount = new YmtCouponSequenceWapper()
                    .selectByPrimaryKey(1).getSequenceCount();

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            verifyReturn(newSequenceCount);

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_079() {
        Logger.start(true, "正例-创建批次-短码-UsePlatforms下单平台限制：APP：8");
        try {

            setLinkCreateCouponBean();

            List<Integer> list = new ArrayList<Integer>();
            list.add(8);

            createcouponBean.setUsePlatforms(list);

            int newSequenceCount = new YmtCouponSequenceWapper()
                    .selectByPrimaryKey(1).getSequenceCount();

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            verifyReturn(newSequenceCount);

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_080() {
        Logger.start(true, "正例-创建批次-短码-UsePlatforms下单平台限制：APP：10");
        try {

            setLinkCreateCouponBean();

            List<Integer> list = new ArrayList<Integer>();
            list.add(10);

            createcouponBean.setUsePlatforms(list);

            int newSequenceCount = new YmtCouponSequenceWapper()
                    .selectByPrimaryKey(1).getSequenceCount();

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            verifyReturn(newSequenceCount);

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_081() {
        Logger.start(true, "正例-创建批次-短码-UsePlatforms下单平台限制：APP：11");
        try {

            setLinkCreateCouponBean();

            List<Integer> list = new ArrayList<Integer>();
            list.add(11);

            createcouponBean.setUsePlatforms(list);

            int newSequenceCount = new YmtCouponSequenceWapper()
                    .selectByPrimaryKey(1).getSequenceCount();

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            verifyReturn(newSequenceCount);

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_082() {
        Logger.start(true, "正例-创建批次-短码-UsePlatforms下单平台限制：WAP：2");
        try {

            setLinkCreateCouponBean();

            List<Integer> list = new ArrayList<Integer>();
            list.add(2);

            createcouponBean.setUsePlatforms(list);

            int newSequenceCount = new YmtCouponSequenceWapper()
                    .selectByPrimaryKey(1).getSequenceCount();

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            verifyReturn(newSequenceCount);

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_083() {
        Logger.start(true, "正例-创建批次-短码-UsePlatforms下单平台限制：WAP：5");
        try {

            setLinkCreateCouponBean();

            List<Integer> list = new ArrayList<Integer>();
            list.add(5);

            createcouponBean.setUsePlatforms(list);

            int newSequenceCount = new YmtCouponSequenceWapper()
                    .selectByPrimaryKey(1).getSequenceCount();

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            verifyReturn(newSequenceCount);

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_084() {
        Logger.start(true, "正例-创建批次-短码-UsePlatforms下单平台限制：WAP：9");
        try {

            setLinkCreateCouponBean();

            List<Integer> list = new ArrayList<Integer>();
            list.add(9);

            createcouponBean.setUsePlatforms(list);

            int newSequenceCount = new YmtCouponSequenceWapper()
                    .selectByPrimaryKey(1).getSequenceCount();

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            verifyReturn(newSequenceCount);

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_085() {
        Logger.start(true, "正例-创建批次-短码-指定限制商品");
        try {

            setLinkCreateCouponBean();

            List<Integer> list = new ArrayList<Integer>();
            list.add(999999);

            createcouponBean.setProductIds(list);

            int newSequenceCount = new YmtCouponSequenceWapper()
                    .selectByPrimaryKey(1).getSequenceCount();

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            verifyReturn(newSequenceCount);

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_086() {
        Logger.start(true, "正例-创建批次-短码-指定限制买手");
        try {

            setLinkCreateCouponBean();

            List<Integer> list = new ArrayList<Integer>();
            list.add(Integer.parseInt(EnvSetup.getData("BuyUserId")));

            createcouponBean.setSellerIds(list);

            int newSequenceCount = new YmtCouponSequenceWapper()
                    .selectByPrimaryKey(1).getSequenceCount();

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            verifyReturn(newSequenceCount);

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_087() {
        Logger.start(true, "正例-创建批次-短码-指定限制活动");
        try {

            setLinkCreateCouponBean();

            List<Integer> list = new ArrayList<Integer>();
            list.add(1234);

            createcouponBean.setActivityIds(list);

            int newSequenceCount = new YmtCouponSequenceWapper()
                    .selectByPrimaryKey(1).getSequenceCount();

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            verifyReturn(newSequenceCount);

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_088() {
        Logger.start(true, "正例-创建批次-短码-指定限制品牌");
        try {

            setLinkCreateCouponBean();

            List<Integer> list = new ArrayList<Integer>();
            list.add(1234);

            createcouponBean.setBrands(list);

            int newSequenceCount = new YmtCouponSequenceWapper()
                    .selectByPrimaryKey(1).getSequenceCount();

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            verifyReturn(newSequenceCount);

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_089() {
        Logger.start(true, "正例-创建批次-短码-指定限制分类");
        try {

            setLinkCreateCouponBean();

            List<Integer> list = new ArrayList<Integer>();
            list.add(1);

            createcouponBean.setCategories(list);

            int newSequenceCount = new YmtCouponSequenceWapper()
                    .selectByPrimaryKey(1).getSequenceCount();

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            verifyReturn(newSequenceCount);

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_090() {
        Logger.start(true, "正例-创建批次-自定义短码优惠卷");
        try {

            setCustomerShortCodeCreateCouponBean();

            List<Integer> list = new ArrayList<Integer>();
            list.add(1);

            createcouponBean.setCategories(list);

            int newSequenceCount = new YmtCouponSequenceWapper()
                    .selectByPrimaryKey(1).getSequenceCount();

            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            verifyReturn(newSequenceCount);

        } catch (Exception e) {
            Logger.fail(e);
        }
    }
    
    @Test
    @Category(P1.class)
    @TestCase
    @Ignore
    public void Tc_CreateCoupon_091() {
        Logger.start(true, "压测，验证创建100w短码需要时间");
        try {

            setDefaultCreateCouponBean();
//            int oldSequenceCount = new YmtCouponSequenceWapper()
//                    .selectByPrimaryKey(1).getSequenceCount();
            
            createcouponBean.setCouponName("yace100wduanma");
            createcouponBean.setCouponNum(1000000);
            
            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

//            verifyReturn(oldSequenceCount);
            
            Date d1 = new Date();

			Logger.comment("开始时间："+d1.toLocaleString());
			
			String batchCode = createcouponCall.getBatchCode();

			YmtCouponBatch batch = new YmtCouponBatchWapper().selectBysBatchCode(batchCode).get(0);
			
			List<YmtCoupon> coupons = new YmtCouponWapper().selectByiBatchId(batch.getiBatchId());

			int flag = 0;
			while (coupons.size() < 1000000 && flag < 50) {
				Thread.sleep(60000);
				coupons = new YmtCouponWapper().selectByiBatchId(batch.getiBatchId());
				flag++;
				
				Logger.comment("第"+flag+"分钟共生成"+coupons.size()+"条记录，当前时间："+new Date().toLocaleString());				
			}
	
			Date d2=new Date();
			Logger.comment("总共花费时间:"+(d2.getTime()-d1.getTime())/(1000*60)+"分钟。");

        } catch (Exception e) {
            Logger.fail(e);
        }
    }
    
    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_092() {
        Logger.start(true, "正例-创建批次-SendType为1:短码发放（需要创建子任务）-创建指定国家优惠券JIRACONN-3005");
        try {

            setDefaultCreateCouponBean();
            int oldSequenceCount = new YmtCouponSequenceWapper()
                    .selectByPrimaryKey(1).getSequenceCount();
            
            List<Integer> countrys=new ArrayList<Integer>();
            countrys.add(1000);
            countrys.add(2000);
            countrys.add(3000);
            
            createcouponBean.setCountrys(countrys);
            
            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            verifyReturn(oldSequenceCount);

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_CreateCoupon_093() {
        Logger.start(true, "正例-创建批次-SendType为2:链接发放(创建子任务)-创建指定国家优惠券-JIRACONN-3005");
        try {
            setLinkCreateCouponBean();

            int newSequenceCount = new YmtCouponSequenceWapper()
                    .selectByPrimaryKey(1).getSequenceCount();

            List<Integer> countrys=new ArrayList<Integer>();
            countrys.add(1000);
            countrys.add(2000);
            countrys.add(3000);
            
            createcouponBean.setCountrys(countrys);
            createcouponCall.setData(createcouponBean);
            createcouponCall.callService();

            verifyReturn(newSequenceCount);

        } catch (Exception e) {
            Logger.fail(e);
        }
    }


    private void setDefaultCreateCouponBean() {
        Logger.comment("设置短码的默认CreateCouponBean");
        createcouponBean.setCouponName("自动化创建优惠券_"
                + TestDataManager.getRandomNum(5));
        createcouponBean.setApplyMemo("自动化测试创建优惠卷");
        createcouponBean.setSendType(1);

        createcouponBean.setEffectiveType(0);
        createcouponBean.setEffectiveValidType(0);
        createcouponBean.setEffectiveDays(0);

        Date dNow = new Date(); // 当前时间
        Date dBefore = new Date();
        Date dAfter = new Date();

        Calendar calendar1 = Calendar.getInstance(); // 得到日历
        calendar1.setTime(dNow);// 把当前时间赋给日历
        calendar1.add(Calendar.DAY_OF_MONTH, -1); // 设置为前一天
        dBefore = calendar1.getTime(); // 得到前一天的时间

        Calendar calendar2 = Calendar.getInstance(); // 得到日历
        calendar2.setTime(dNow);// 把当前时间赋给日历
        calendar2.add(Calendar.DAY_OF_MONTH, 10); // 设置为后十天
        dAfter = calendar2.getTime(); // 得到前一天的时间

        createcouponBean.setValidStart(dBefore);
        createcouponBean.setValidEnd(dAfter);

        createcouponBean.setCouponUseType(1);

        CouponValue couponValue = new CouponValue();
        couponValue.setOrderMinAmount(new BigDecimal(200));
        couponValue.setDeductionMaxAmount(new BigDecimal(10));

        List<CouponValue> couponValues = new ArrayList<CouponValue>();
        couponValues.add(couponValue);

        createcouponBean.setCouponValues(couponValues);
        createcouponBean.setCouponNum(20);
        createcouponBean.setPerCouponMaxUseCount(2);
        createcouponBean.setPerUserReceiveMaxCount(2);

        createcouponBean.setIsCustomCouponCode(false);
        createcouponBean.setCustomCouponCode("");

        createcouponBean.setUserType(0);
        createcouponBean.setCouponDes("优惠券描述可显示给买家看");

        List<Integer> usePlatforms = new ArrayList<Integer>();
        usePlatforms.add(1);
        usePlatforms.add(2);
        usePlatforms.add(3);

        createcouponBean.setUsePlatforms(usePlatforms);

        List<Integer> productIds = new ArrayList<Integer>();
        createcouponBean.setProductIds(productIds);

        List<Integer> sellerIds = new ArrayList<Integer>();
        createcouponBean.setProductIds(sellerIds);

        List<Integer> activityIds = new ArrayList<Integer>();
        createcouponBean.setProductIds(activityIds);

        List<Integer> brands = new ArrayList<Integer>();
        createcouponBean.setProductIds(brands);

        List<Integer> categories = new ArrayList<Integer>();
        createcouponBean.setProductIds(categories);

        createcouponBean.setApplyUser("自动化user111");
        createcouponBean.setDepartment(1);
        createcouponBean.setImpresetInvoiceId("111111");
        createcouponBean.setOperatorId(222222);
    }

    private void setLinkCreateCouponBean() {
        Logger.comment("设置链接的默认CreateCouponBean");
        setDefaultCreateCouponBean();

        createcouponBean.setPerCouponMaxUseCount(1);
        createcouponBean.setSendType(2);
    }

    private void setCustomerShortCodeCreateCouponBean() {
        Logger.comment("设置自定义短码优惠卷CreateCouponBean");
        setDefaultCreateCouponBean();
        createcouponBean.setSendType(1);
        createcouponBean.setIsCustomCouponCode(true);
        createcouponBean.setCustomCouponCode("shortcode"
                + TestDataManager.getRandomNum(10));
        createcouponBean.setCouponNum(1);
    }

    private void setCustomerLinkCreateCouponBean() {
        Logger.comment("设置自定义短码优惠卷CreateCouponBean");
        setDefaultCreateCouponBean();
        createcouponBean.setSendType(2);
        createcouponBean.setIsCustomCouponCode(true);
        createcouponBean.setCustomCouponCode("link_"
                + TestDataManager.getRandomNum(10));
        createcouponBean.setPerCouponMaxUseCount(1);
    }

    private void verifyReturn(int oldCouponSequence)
            throws InterruptedException {

        Logger.verifyEquals("0", createcouponCall.getCode(), "验证返回code");
        Logger.verifyEquals("操作成功！", createcouponCall.getMessage(),
                "验证返回Message");
        Logger.verifyEquals(false, createcouponCall.getBatchCode().isEmpty(),
                "验证返回BatchCode非空");

        String batchCode = createcouponCall.getBatchCode();

        // 验证表Ymt_CouponBatch表
        YmtCouponBatch ymtCouponBatch = checkYmtCouponBatch(batchCode);

        // 验证表Ymt_CouponValue表
        checkYmtCouponValue(ymtCouponBatch.getiCouponSettingId());

        // 验证表Ymt_CouponSetting表
        YmtCouponSetting ymtCouponSetting = checkYmtCouponSetting(ymtCouponBatch);

        // 验证表Ymt_CouponScenario表
        checkYmtCouponScenario(ymtCouponSetting.getiScenarioId());

        // 验证表Ymt_CouponGenerateTask表
        YmtCouponGenerateTask task = checkYmtCouponGenerateTask(ymtCouponBatch);

        // 验证表Ymt_CouponGenerateSubTask表
        if (task != null) {
            checkYmtCouponGenerateSubTask(task);
        }

        // 验证表Ymt_CouponSequence表
        checkYmtCouponSequence(1, oldCouponSequence);

        // 验证表Ymt_Coupon表
        checkYmtCoupon(ymtCouponBatch.getiBatchId(), ymtCouponSetting);
    }

    private YmtCouponBatch checkYmtCouponBatch(String batchCode) {
        Logger.comment("====方法：验证数据库YmtCouponBatch====");

        List<YmtCouponBatch> ymtCouponBatchs = new YmtCouponBatchWapper()
                .selectBysBatchCode(batchCode);

        Logger.verifyEquals(1, ymtCouponBatchs.size(),
                "验证Ymt_CouponBatch表生成sBatchCode=" + batchCode + "的条数。");

        if (ymtCouponBatchs.size() >= 1) {
            YmtCouponBatch batchItem = ymtCouponBatchs.get(0);

            Logger.verifyEquals(
                    createcouponBean.getDepartment(),
                    Integer.parseInt(batchItem.getApplyDepartment().toString()),
                    "验证数据库Ymt_CouponBatch表中ApplyDepartment");
            // 平台创建
            Logger.verifyEquals(1, batchItem.getiBatchCreateType().intValue(),
                    "验证数据库Ymt_CouponBatch表中iBatchCreateType");
            Logger.verifyEquals(createcouponBean.getCouponName(),
                    batchItem.getsCouponName(),
                    "验证数据库Ymt_CouponBatch表中sCouponName");
            Logger.verifyEquals(createcouponBean.getPerUserReceiveMaxCount(),
                    batchItem.getiCouponNumPerUser(),
                    "验证数据库Ymt_CouponBatch表中iCouponNumPerUser");

            Logger.verifyEquals(createcouponBean.getCouponNum(),
                    batchItem.getiCouponTotalNum(),
                    "验证数据库Ymt_CouponBatch表中iCouponNumPerUser");

            Logger.verifyEquals(createcouponBean.getImpresetInvoiceId(),
                    batchItem.getImpresetInvoiceId(),
                    "验证数据库Ymt_CouponBatch表中iCouponNumPerUser");

            Logger.verifyEquals(false, batchItem.getbInvalidStatus(),
                    "验证数据库Ymt_CouponBatch表中bInvalidStatus");

            Logger.verifyEquals("", batchItem.getInvalidUser(),
                    "验证数据库Ymt_CouponBatch表中InvalidUser");

            Logger.verifyEquals(createcouponBean.getOperatorId(),
                    batchItem.getiOperatorId(),
                    "验证数据库Ymt_CouponBatch表中iOperatorId");

            Logger.verifyEquals(createcouponBean.getSendType(),
                    batchItem.getiSendType(), "验证数据库Ymt_CouponBatch表中iSendType");

            // 普通优惠卷(发现用于生成BatchPrefix的第一个字母)
            Logger.verifyEquals(1, batchItem.getiUsage(),
                    "验证数据库Ymt_CouponBatch表中iUsage");
            
            // 新加字段
            Logger.verifyEquals(createcouponBean.getCouponDes(), batchItem.getCouponDes(),
                    "验证数据库Ymt_CouponBatch表中iUsage");


            return batchItem;
        }

        return null;
    }

    private void checkYmtCouponValue(int iCouponSettingId) {
        // 验证Ymt_CouponValue表
        Logger.comment("====方法：验证数据库YmtCouponValue====");

        List<YmtCouponValue> valuelist = new YmtCouponValueWapper()
                .selectByiCouponSettingId(iCouponSettingId);

        Logger.verifyEquals(createcouponBean.getCouponValues().size(),
                valuelist.size(), "验证Ymt_CouponValue表生成iCouponSettingId="
                        + iCouponSettingId + "条数正确");

        for (int i = 0; i < valuelist.size(); i++) {
            YmtCouponValue valueItem = valuelist.get(i);
            CouponValue couponValue = createcouponBean.getCouponValues().get(i);
            Logger.verifyEquals(couponValue.getDeductionMaxAmount(),
                    new BigDecimal(valueItem.getFcouponvalue().floatValue()),
                    "验证数据库Ymt_CouponValue表中Fcouponvalue");
            Logger.verifyEquals(couponValue.getOrderMinAmount(),
                    new BigDecimal(valueItem.getFminordervalue().floatValue()),
                    "验证数据库Ymt_CouponValue表中Fminordervalue");
        }
    }

    private YmtCouponSetting checkYmtCouponSetting(YmtCouponBatch batchItem) {
        Logger.comment("====方法：验证数据库YmtCouponSetting====");

        List<YmtCouponSetting> settinglist = new YmtCouponSettingWapper()
                .selectByiCouponSettingId(batchItem.getiCouponSettingId());

        Logger.verifyEquals(
                1,
                settinglist.size(),
                "验证Ymt_CouponSetting表生成iCouponSettingId="
                        + batchItem.getiCouponSettingId() + "条数正确");

        if (settinglist.size() >= 1) {
            YmtCouponSetting settingItem = settinglist.get(0);

            Logger.verifyEquals(createcouponBean.getApplyMemo(),
                    settingItem.getsApplyMemo(),
                    "验证数据库Ymt_CouponSetting表中sApplyMemo");

            Logger.verifyEquals(createcouponBean.getApplyUser(),
                    settingItem.getsApplyUser(),
                    "验证数据库Ymt_CouponSetting表中sApplyUser");

            Logger.verifyEquals(createcouponBean.getPerCouponMaxUseCount(),
                    settingItem.getiCouponUseCount(),
                    "验证数据库Ymt_CouponSetting表中iCouponUseCount");

            Logger.verifyEquals(createcouponBean.getCouponUseType(),
                    settingItem.getiCouponUseType(),
                    "验证数据库Ymt_CouponSetting表中iCouponUseType");

            Logger.verifyEquals(createcouponBean.getEffectiveDays(),
                    settingItem.getiEffectiveDays(),
                    "验证数据库Ymt_CouponSetting表中iEffectiveDays");

            Logger.verifyEquals(createcouponBean.getEffectiveType(),
                    settingItem.getiEffectiveType(),
                    "验证数据库Ymt_CouponSetting表中iEffectiveType");

            Logger.verifyEquals(createcouponBean.getEffectiveValidType(),
                    settingItem.getiEffectiveValidType(),
                    "验证数据库Ymt_CouponSetting表中iEffectiveValidType");

            Logger.verifyEquals(false, settingItem.getbIsMobileVerify(),
                    "验证数据库Ymt_CouponSetting表中bIsMobileVerify");

            Logger.verifyEquals(
                    batchItem.getiCouponTotalNum()
                            * settingItem.getiCouponUseCount(),
                    settingItem.getiMaxUseTime(),
                    "验证数据库Ymt_CouponSetting表中iMaxUseTime");

            Logger.verifyEquals(createcouponBean.getPerUserReceiveMaxCount(),
                    settingItem.getiMaxUseTimePerUser(),
                    "验证数据库Ymt_CouponSetting表中iMaxUseTimePerUser");

            Logger.verifyEquals(0, settingItem.getiReceiveCount(),
                    "验证数据库Ymt_CouponSetting表中iReceiveCount");

            if (isNullOrEmplty(createcouponBean.getSellerIds())
                    && isNullOrEmplty(createcouponBean.getProductIds())
                    && isNullOrEmplty(createcouponBean.getActivityIds())
                    && isNullOrEmplty(createcouponBean.getBrands())
                    && isNullOrEmplty(createcouponBean.getCategories())) {
                Logger.verifyEquals(1, settingItem.getiScenarioType(),
                        "验证数据库Ymt_CouponSetting表中iScenarioType");
            } else {
                Logger.verifyEquals(2, settingItem.getiScenarioType(),
                        "验证数据库Ymt_CouponSetting表中iScenarioType");
            }

            Logger.verifyEquals(settingItem.getiMaxUseTime(),
                    settingItem.getiUseTotalCount(),
                    "验证数据库Ymt_CouponSetting表中iUseTotalCount");

            if (settingItem.getiEffectiveValidType() == 0) {
                Logger.verifyEquals(createcouponBean.getValidStart()
                        .toLocaleString(), settingItem.getdValidStart()
                        .toLocaleString(),
                        "验证数据库Ymt_CouponSetting表中dValidStart");
                // 验证setting.ValidEnd = request.ValidEnd.Value.Date.AddDays(1);

                Date date = createcouponBean.getValidEnd();
                Date dnew = new Date();

                Calendar calendar1 = Calendar.getInstance(); // 得到日历
                calendar1.setTime(date);// 把当前时间赋给日历
                calendar1.add(Calendar.DAY_OF_MONTH, +1); // 设置为前一天
                dnew = calendar1.getTime(); // 得到前一天的时间

                SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
                String dateString = formatter.format(date) + " 23:59:59";
                SimpleDateFormat formatter2 = new SimpleDateFormat(
                        "yyyy-MM-dd HH:mm:ss");
                Logger.verifyEquals(dateString,
                        formatter2.format(settingItem.getdValidEnd()),
                        "验证数据库Ymt_CouponSetting表中dValidEnd");

            } else {
                Logger.verifyEquals(new Date("1900-1-1"),
                        settingItem.getdValidStart(),
                        "验证数据库Ymt_CouponSetting表中dValidStart");

                Logger.verifyEquals(new Date("1900-01-01 23:59:59"),
                        settingItem.getdValidEnd(),
                        "验证数据库Ymt_CouponSetting表中dValidEnd");
            }

            Logger.verifyEquals(createcouponBean.getEffectiveValidType(),
                    settingItem.getiEffectiveValidType(),
                    "验证数据库Ymt_CouponSetting表中iEffectiveValidType");

            return settingItem;
        }
        return null;
    }

    private void checkYmtCouponScenario(int iCouponScenarioId) {
        Logger.comment("====方法：验证数据库YmtCouponScenario====");

        List<YmtCouponScenario> scenariolist = new YmtCouponScenarioWapper()
                .selectByiCouponScenarioId(iCouponScenarioId);

        Logger.verifyEquals(1, scenariolist.size(),
                "验证Ymt_CouponScenario表生成iCouponScenarioId=" + iCouponScenarioId
                        + "条数正确");

        if (scenariolist.size() >= 1) {
            YmtCouponScenario scenarioItem = scenariolist.get(0);

            if (createcouponBean.getActivityIds() != null
                    && createcouponBean.getActivityIds().size() > 0) {
                Logger.verifyEquals(getList(createcouponBean.getActivityIds()),
                        scenarioItem.getSactivityids(),
                        "验证数据库Ymt_CouponScenario表中Sactivityids");
            } else {
                Logger.verifyEquals(null, scenarioItem.getSactivityids(),
                        "验证数据库Ymt_CouponScenario表中Sactivityids");
            }

            Logger.verifyEquals(null, scenarioItem.getSlogisticstypes(),
                    "验证数据库Ymt_CouponScenario表中Slogisticstypes");

            if (createcouponBean.getBrands() != null
                    && createcouponBean.getBrands().size() > 0) {
                Logger.verifyEquals(getList(createcouponBean.getBrands()),
                        scenarioItem.getSproductbrands(),
                        "验证数据库Ymt_CouponScenario表中Sproductbrands");
            } else {
                Logger.verifyEquals(null, scenarioItem.getSproductbrands(),
                        "验证数据库Ymt_CouponScenario表中Sproductbrands");
            }

            if (createcouponBean.getCategories() != null
                    && createcouponBean.getCategories().size() > 0) {
                Logger.verifyEquals(getList(createcouponBean.getCategories()),
                        scenarioItem.getSproductcategories(),
                        "验证数据库Ymt_CouponScenario表中Sproductcategories");
            } else {
                Logger.verifyEquals(null, scenarioItem.getSproductcategories(),
                        "验证数据库Ymt_CouponScenario表中Sproductcategories");
            }

            if (createcouponBean.getSellerIds() != null
                    && createcouponBean.getSellerIds().size() > 0) {
                Logger.verifyEquals(getList(createcouponBean.getSellerIds()),
                        scenarioItem.getSsellerids(),
                        "验证数据库Ymt_CouponScenario表中Ssellerid");
            } else {
                Logger.verifyEquals(null, scenarioItem.getSsellerids(),
                        "验证数据库Ymt_CouponScenario表中Ssellerid");
            }

            if (createcouponBean.getProductIds() != null
                    && createcouponBean.getProductIds().size() > 0) {
                Logger.verifyEquals(getList(createcouponBean.getProductIds()),
                        scenarioItem.getSspecificproducts(),
                        "验证数据库Ymt_CouponScenario表中Sspecificproducts");
            } else {
                Logger.verifyEquals(null, scenarioItem.getSspecificproducts(),
                        "验证数据库Ymt_CouponScenario表中Sspecificproducts");
            }

            Logger.verifyEquals(null, scenarioItem.getSstockstatus(),
                    "验证数据库Ymt_CouponScenario表中Sstockstatus");

            if (createcouponBean.getUsePlatforms() != null
                    && createcouponBean.getUsePlatforms().size() > 0) {
                Logger.verifyEquals(
                        getList(createcouponBean.getUsePlatforms()),
                        scenarioItem.getSuseplatforms(),
                        "验证数据库Ymt_CouponScenario表中Suseplatforms");
            } else {
                Logger.verifyEquals(null, scenarioItem.getSuseplatforms(),
                        "验证数据库Ymt_CouponScenario表中Suseplatforms");
            }

            Logger.verifyEquals(null, scenarioItem.getSuserlevels(),
                    "验证数据库Ymt_CouponScenario表中Suserlevels");

            Logger.verifyEquals(createcouponBean.getUserType(),
                    scenarioItem.getIusertype(),
                    "验证数据库Ymt_CouponScenario表中Iusertype");
            
            if (createcouponBean.getCountrys() != null
                    && createcouponBean.getCountrys().size() > 0) {
                Logger.verifyEquals(getList(createcouponBean.getCountrys()),
                        scenarioItem.getScountrys(),
                        "验证数据库Ymt_CouponScenario表中sCountrys");
            } else {
                Logger.verifyEquals(null, scenarioItem.getScountrys(),
                        "验证数据库Ymt_CouponScenario表中sCountrys");
            }
        }
    }

    private YmtCouponGenerateTask checkYmtCouponGenerateTask(
            YmtCouponBatch batchItem) throws InterruptedException {
        Logger.comment("====方法：验证数据库YmtCouponGenerateTask====");
        // Thread.sleep(20000);
        YmtCouponGenerateTaskWapper ymtCouponGenerateTaskWapper = new YmtCouponGenerateTaskWapper();
        List<YmtCouponGenerateTask> tasks = ymtCouponGenerateTaskWapper
                .selectByCouponBatchId(batchItem.getiBatchId());

        // 短码会创建task、subtask跟ymt_coupon
        // 自定义短码优惠券不会生成task跟subtask
        if (createcouponBean.getSendType() == 1
                && !createcouponBean.getIsCustomCouponCode()) {
            // 验证Ymt_CouponGenerateTask表
            Logger.verifyEquals(
                    1,
                    tasks.size(),
                    "验证Ymt_CouponGenerateTask表生成CouponBatchId="
                            + batchItem.getiBatchId() + "条数正确");

            if (tasks.size() >= 1) {
                YmtCouponGenerateTask task = tasks.get(0);

                int flag = 0;
                while (task.getTaskStatus() != 2 && flag < 100) {
                    Thread.sleep(1000);
                    task = ymtCouponGenerateTaskWapper.selectByCouponBatchId(
                            batchItem.getiBatchId()).get(0);
                    flag++;
                }

                Logger.verifyEquals(createcouponBean.getCouponNum(),
                        task.getTaskGenerateCount(),
                        "验证数据库Ymt_CouponGenerateTask表中TaskGenerateCount");

                Logger.verifyEquals(2, task.getTaskStatus().intValue(),
                        "验证数据库Ymt_CouponGenerateTask表中TaskStatus");

                Logger.verifyEquals(createcouponBean.getCouponNum(), task.getTaskHadGenerateCount(),
                        "验证数据库Ymt_CouponGenerateTask表中TaskHadGenerateCount");

                return task;
            } else {
                Logger.verifyEquals(
                        0,
                        tasks.size(),
                        "验证Ymt_CouponGenerateTask表生成CouponBatchId="
                                + batchItem.getiBatchId() + "条数正确");
            }

        }

        return null;
    }

    private void checkYmtCouponGenerateSubTask(YmtCouponGenerateTask task) {
        Logger.comment("====方法：验证数据库YmtCouponGenerateSubTask====");

        List<YmtCouponGenerateSubTask> subTasks = new YmtCouponGenerateSubTaskWapper()
                .selectByTaskId(task.getTaskId());

        int mode = createcouponBean.getCouponNum() % 1000;
        int num = createcouponBean.getCouponNum() / 1000;

        if (mode != 0) {
            num++;
        }

        Logger.verifyEquals(num, subTasks.size(),
                "验证数据库Ymt_CouponGenerateSubTask表中taskid=" + task.getTaskId()
                        + "的条数");

        for (int i = 0; i < num; i++) {
            YmtCouponGenerateSubTask subTask = subTasks.get(i);

            Logger.verifyEquals(1, subTask.getSubTaskExecuteTims().intValue(),
                    "验证数据库Ymt_CouponGenerateSubTask表中SubTaskExecuteTims");

            if (createcouponBean.getSendType() == 1) {
                Logger.verifyEquals(true, subTask.getSubTaskNo() > 0,
                        "验证数据库Ymt_CouponGenerateSubTask表中SendType");
            } else {
                Logger.verifyEquals(null, subTask.getSubTaskNo(),
                        "验证数据库Ymt_CouponGenerateSubTask表中SendType");
            }
        }
    }

    private void checkYmtCouponSequence(int sequenceId, int oldCouponSequence) {
        Logger.comment("====方法：验证数据库YmtYmtCouponSequence====");

        int mode = createcouponBean.getCouponNum() % 1000;
        int num = createcouponBean.getCouponNum() / 1000;

        if (mode != 0) {
            num++;
        }

        // 短码发放 时会修改Ymt_CouponSequence表
        int newSequenceCount = new YmtCouponSequenceWapper()
                .selectByPrimaryKey(1).getSequenceCount();
        if (createcouponBean.getSendType() == 1 && !createcouponBean.getIsCustomCouponCode())
        {
            Logger.verifyEquals(num, newSequenceCount - oldCouponSequence,
                    "验证数据库Ymt_CouponSequence表中SequenceCount");
        }
        else {
            Logger.verifyEquals(0, newSequenceCount - oldCouponSequence,
                    "验证数据库Ymt_CouponSequence表中SequenceCount");
        }
    }

    private void checkYmtCoupon(int iBatchId, YmtCouponSetting settingItem) {
        Logger.comment("====方法：验证数据库YmtCoupon====");

        List<YmtCoupon> coupons = new YmtCouponWapper()
                .selectByiBatchId(iBatchId);

        if (createcouponBean.getSendType() == 1
                || createcouponBean.getSendType() == 2
                && createcouponBean.getIsCustomCouponCode()) {

            Logger.verifyEquals(createcouponBean.getCouponNum(),
                    coupons.size(), "验证Ymt_Coupon表生成BatchId=" + iBatchId
                            + "条数正确");

            int num = 1;
            for (YmtCoupon coupon : coupons) {
                Logger.comment("验证第" + num + "条记录，CouponCode：" + coupon.getsCouponCode());
                num++;
                Logger.verifyEquals(settingItem.getiCouponSettingId(),
                        coupon.getiCouponSetting(),
                        "验证数据库Ymt_Coupon表中iCouponSettingId");
                Logger.verifyEquals(createcouponBean.getSendType(),
                        coupon.getiCouponType(), "验证数据库Ymt_Coupon表中SendType");
                Logger.verifyEquals(1, coupon.getiUsage(),
                        "验证数据库Ymt_Coupon表中iUsage");
                Logger.verifyEquals(settingItem.getdValidStart(),
                        coupon.getdValidStart(), "验证数据库Ymt_Coupon表中dValidStart");
                Logger.verifyEquals(settingItem.getdValidEnd(),
                        coupon.getdValidEnd(), "验证数据库Ymt_Coupon表中dValidEnd");

                if (createcouponBean.getIsCustomCouponCode() == true) {
                    Logger.verifyEquals(createcouponBean.getCustomCouponCode(),
                            coupon.getsCouponCode(),
                            "验证数据库Ymt_Coupon表中CouponCode");
                }
            }
        }
    }

    private String getList(List<Integer> list) {
        StringBuffer sBuffer = new StringBuffer();
        for (Integer integer : list) {
            sBuffer.append(integer);
            sBuffer.append(",");
        }
        if (sBuffer.length() > 0) {
            sBuffer.deleteCharAt(sBuffer.length() - 1);
        }
        return sBuffer.toString();
    }

    private boolean isNullOrEmplty(List<Integer> list) {
        return list == null || list.size() == 0;
    }

}
